package ch.ethz.inf.shop.model.simpleDatabase.operators;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import ch.ethz.inf.shop.model.simpleDatabase.Tuple;

public class Insert extends Operator {

	final String fileName;

	public Insert(String fileName) {
		this.fileName = fileName;
	}

	public void makeInsert(List<Tuple> tuples) throws IOException {

		String lineSeparatorChar = System.getProperty("line.separator");
		FileWriter fstream = new FileWriter(fileName, true);
		BufferedWriter out = new BufferedWriter(fstream);
		for (Tuple tuple : tuples) {
			for (int i = 0; i < tuple.getSchema().getColumnNames().size(); i++) {
				out.write(tuple.getString(i));
				if (i != (tuple.getSchema().getColumnNames().size() - 1)) {
					out.write(";");
				}
			}
			out.write(lineSeparatorChar);
		}
		out.flush();
		// Close the output stream
		out.close();

	}

	@Override
	public boolean moveNext() {
		// TODO Auto-generated method stub
		return false;
	}

}
